10 ' 外包装箱打印程序
20 ' 泛海数据科技有限公司
30 ' 2019年4月

100 ' INIT
110 BREAK 0, 1 : '按F1键退出
120 BREAK 0 ON
130 ON BREAK 0 GOSUB HANDLECANCEL
140 ON ERROR GOTO HANDLEERR
140 OPEN "console:" AS 1
150 OPEN "uart1:" FOR INPUT AS 2
160 NASC 8
180 DIM PARTS$(13)
210 MARGINX% = 20
220 YTOP% = 1050
230 MARGINX2% = 400
240 MARGINX3% = 688
242 MARGINX4% = 1018
244 LINEHEIGHT% = 112
250 OPTIMIZE "BATCH" ON
260 DIM TITLES$(9)
270 TITLES$(0) = "箱号PKGID"
280 TITLES$(1) = "描述DESC"
290 TITLES$(2) = "编码ITEM"
300 TITLES$(3) = "数量QTY"
310 TITLES$(4) = "代码CODE"
320 TITLES$(5) = "批次号LOT NO"
330 TITLES$(6) = "日期"
340 TITLES$(7) = "供应商型号MPN"
350 TITLES$(8) = "备注"

900 PRINT "RUN LOOP"
910 PRINT #1: PRINT #1, "WAIT COM1"

1000 LOOP: LINE INPUT #2, IN$
1010 IF IN$="" THEN BEEP: GOTO LOOP
1020 IF IN$="END" THEN BEEP: GOTO EXIT

1100 C%=SPLIT(IN$,"PARTS$",64) :' @=64 AS separator
1110 IF C%<>13 THEN BEEP: GOTO LOOP

1980 ALIGN 7: DIR 1
1990 FONT "FangSong",8,0,100

2000 PRPOS MARGINX%, YTOP%
2010 PRTXT TITLES$(0)
2020 PRPOS 400, YTOP%
2030 BARSET "CODE128",2,1,3,70
2040 BARFONT "Univers",6,0,5,1,1,100 ON
2050 PRBAR PARTS$(0)
2060 FOR I% = 1 TO 8
2070 PRPOS MARGINX%, YTOP% - LINEHEIGHT% * I%
2080 PRTXT TITLES$(I%) + ":"
2090 PRPOS 400, YTOP%  - LINEHEIGHT% * I%
2100 PRTXT PARTS$(I%)
2110 NEXT

2200 BARFONT OFF
2210 PRPOS MARGINX3%, 820
2220 BARSET "QRCODE",1,1,4,2,2
2230 PRBAR PARTS$(9)
2240 PRPOS MARGINX4%, 820
2250 BARSET "QRCODE",1,1,4,2,2
2260 PRBAR PARTS$(10)
2270 PRPOS MARGINX3%, 485
2280 BARSET "QRCODE",1,1,4,2,2
2290 PRBAR PARTS$(11)
2300 PRPOS MARGINX4%, 485 
2310 BARSET "QRCODE",1,1,4,2,2
2320 PRBAR PARTS$(12)

2990 PRINTFEED
3000 'GOTO LOOP

10000 EXIT: ' EXIT
10010 CLOSE 1
10020 CLOSE 2
10030 PRINT "END"
10040 END

15000 HANDLEERR: BEEP: BEEP: BEEP : BEEP: BEEP: BEEP
15010 PRINT "ERROR", ERL, ERR
15020 GOTO EXIT

20000 HANDLECANCEL: ' CANCELED
20010 GOTO EXIT